package com.sgb.kjwl.view.ui.adapter.self;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.OilInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter2;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class OilListAdapter extends BaseRecycleAdapter2<OilInfoEntity> {
    clickButtonListener listener;
    public OilListAdapter(Context context,  List<OilInfoEntity> datas) {
        super(context, R.layout.item_oil_state, datas);
    }

    public void setListener(clickButtonListener listener) {
        this.listener = listener;
    }

    @Override
    public void convert(ItemViewHolder holder, OilInfoEntity entity, int position) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvStatus=holder.itemView.findViewById(R.id.tv_state);
        TextView off_view=holder.itemView.findViewById(R.id.off_view);
        TextView online_view=holder.itemView.findViewById(R.id.online_view);
        TextView edit_view=holder.itemView.findViewById(R.id.edit_view);

        switch (entity.getState()){
            case "0":
                tvStatus.setText("已下架");
                online_view.setVisibility(View.VISIBLE);
                off_view.setVisibility(View.GONE);
                break;
            case "1":
                tvStatus.setText("已上架");
                online_view.setVisibility(View.GONE);
                off_view.setVisibility(View.VISIBLE);
                break;

        }
        off_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.putAway(position,entity.getId(),0);
                }
            }
        });
        online_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.putAway(position,entity.getId(),1);
                }
            }
        });
        edit_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.edite(entity);
                }
            }
        });
    }

   public interface  clickButtonListener{
        void putAway(int pos,int id,int type);
        void edite(OilInfoEntity oilInfoEntity);
    }
}
